import { IProject } from 'screens/project-list/list'
import { useHttp } from './http'
import { useAsync } from './use-async'

export const useEditProject = () => {
  const { run, ...AsyncResult } = useAsync()
  const client = useHttp()
  const mutate = (params: Partial<IProject>) => {
    return run(
      client(`projects/${params.id}`, {
        method: 'PATCH',
        data: params
      })
    )
  }
  return { mutate, ...AsyncResult }
}

export const useAddProject = () => {
  const { run, ...AsyncResult } = useAsync()
  const client = useHttp()
  const mutate = (params: Partial<IProject>) => {
    return run(
      client(`projects/${params.id}`, {
        data: params,
        method: 'POST'
      })
    )
  }
  return { mutate, ...AsyncResult }
}
